package org.testis.utils;

import java.io.IOException;


/**
 *
 * @author nurhat
 */
public class DevconUtils
{

    public static boolean isDeviceExist(String pnpInstanceID) throws IOException,
                                                                     InterruptedException
    {
        TerminalApplicationExecutor exec = new TerminalApplicationExecutor(
            "devcon find ",
            "\"@" + pnpInstanceID + "\"");

        exec.runExec();

        if (!exec.getOutputString().contains("No matching devices found")) {
            return true;
        }
        else {
            return false;
        }
    }


    public static boolean isDeviceDisabled(String pnpInstanceID) throws
        IOException, InterruptedException
    {
        TerminalApplicationExecutor exec = new TerminalApplicationExecutor(
            "devcon status ",
            "\"@" + pnpInstanceID + "\"");

        exec.runExec();

        if (exec.getOutputString().contains("Device is disabled")) {
            return true;
        }
        else {
            return false;
        }
    }


    public static boolean disableDevice(String pnpInstanceID) throws IOException,
                                                                     InterruptedException
    {
        TerminalApplicationExecutor exec = new TerminalApplicationExecutor(
            "devcon disable ",
            "\"@" + pnpInstanceID + "\"");

        exec.runExec();

        if (!exec.getOutputString().contains("No devices disabled")) {
            return true;
        }
        else {
            return false;
        }
    }


    public static boolean enableDevice(String pnpInstanceID) throws IOException,
                                                                    InterruptedException
    {
        TerminalApplicationExecutor exec = new TerminalApplicationExecutor(
            "devcon enable ",
            "\"@" + pnpInstanceID + "\"");

        exec.runExec();

        if (!exec.getOutputString().contains("No devices enabled")) {
            return true;
        }
        else {
            return false;
        }
    }


    public static boolean isDeviceRunning(String pnpInstanceID) throws
        IOException, InterruptedException
    {
        TerminalApplicationExecutor exec = new TerminalApplicationExecutor(
            "devcon status ",
            "\"@" + pnpInstanceID + "\"");

        exec.runExec();

        if (exec.getOutputString().contains("Driver is running")) {
            return true;
        }
        else {
            return false;
        }
    }
}
